-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prevent duplicate tokens being added in adminJS #1852
prevent duplicate tokens being added in adminJS #1852
Conversation
WalkthroughThe changes focus on the Changes
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (duplicateSymbol || duplicateAddress) { | ||
message = `Token ${ | ||
duplicateAddress ? 'address' : 'symbol' | ||
} already exists!`; | ||
type = 'danger'; | ||
return { | ||
record: {}, | ||
notice: { | ||
message, | ||
type, | ||
}, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error message to reflect all duplicate fields
When both the token address and symbol already exist, the current error message only indicates one of them. To provide clearer feedback to the user, consider updating the error message to list all duplicate fields that are causing the conflict.
Apply this diff to enhance the error message:
if (duplicateSymbol || duplicateAddress) {
- message = `Token ${
- duplicateAddress ? 'address' : 'symbol'
- } already exists!`;
+ let duplicateFields = [];
+ if (duplicateAddress) duplicateFields.push('address');
+ if (duplicateSymbol) duplicateFields.push('symbol');
+ const fields = duplicateFields.join(' and ');
+ message = `Token ${fields} already exist${duplicateFields.length > 1 ? '' : 's'}!`;
type = 'danger';
return {
record: {},
notice: {
message,
type,
},
};
}
This change ensures that if both the address and symbol are duplicates, the error message will inform the user accordingly.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (duplicateSymbol || duplicateAddress) { | |
message = `Token ${ | |
duplicateAddress ? 'address' : 'symbol' | |
} already exists!`; | |
type = 'danger'; | |
return { | |
record: {}, | |
notice: { | |
message, | |
type, | |
}, | |
}; | |
} | |
if (duplicateSymbol || duplicateAddress) { | |
let duplicateFields = []; | |
if (duplicateAddress) duplicateFields.push('address'); | |
if (duplicateSymbol) duplicateFields.push('symbol'); | |
const fields = duplicateFields.join(' and '); | |
message = `Token ${fields} already exist${duplicateFields.length > 1 ? '' : 's'}!`; | |
type = 'danger'; | |
return { | |
record: {}, | |
notice: { | |
message, | |
type, | |
}, | |
}; | |
} |
if (!address || !decimals || !name || !networkId || !symbol) { | ||
message = 'Please fill all required fields'; | ||
type = 'danger'; | ||
return { | ||
notice: { | ||
message, | ||
type, | ||
}, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate 'decimals' is a valid number
Currently, 'decimals' is only checked for a truthy value. If 'decimals' cannot be converted to a valid number, Number(decimals)
will result in NaN
, which may cause issues when saving the token. Consider adding a validation check to ensure 'decimals' is a valid number before proceeding.
Apply this diff to improve validation:
if (!address || !decimals || !name || !networkId || !symbol) {
message = 'Please fill all required fields';
type = 'danger';
return {
notice: {
message,
type,
},
};
}
+ if (isNaN(Number(decimals))) {
+ message = 'Decimals must be a valid number';
+ type = 'danger';
+ return {
+ notice: {
+ message,
+ type,
+ },
+ };
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (!address || !decimals || !name || !networkId || !symbol) { | |
message = 'Please fill all required fields'; | |
type = 'danger'; | |
return { | |
notice: { | |
message, | |
type, | |
}, | |
}; | |
} | |
if (!address || !decimals || !name || !networkId || !symbol) { | |
message = 'Please fill all required fields'; | |
type = 'danger'; | |
return { | |
notice: { | |
message, | |
type, | |
}, | |
}; | |
} | |
if (isNaN(Number(decimals))) { | |
message = 'Decimals must be a valid number'; | |
type = 'danger'; | |
return { | |
notice: { | |
message, | |
type, | |
}, | |
}; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @RamRamez
#1777
Summary by CodeRabbit
New Features
Bug Fixes